#include"common.hpp"

extern Log log;

int main(){
    int shimid = GetShm(); // 连接共享区
    log(DEBUG,"get shm done");


    int fd = open(FIFO_FILE,O_WRONLY); // 连接管道
    if(fd<0)
    {
        log(FATAL,"error string:%s, error code %d",strerror(errno),errno);
        exit(FIFO_OPEN_ERROR);
    }

    char* shmaddr = (char*)shmat(shimid,nullptr,0);
    log(DEBUG,"attach shm done, shmaddr: 0x%x",shmaddr);

    while (true)
    {
        /* code */
        cout<<"please enter@ ";
        fgets(shmaddr,4096,stdin);
        // memcpy(shmaddr,buffer,sizeof(buffer) + 1);

        write(fd,"c",1); // 通知对方读取
    }
    

    shmdt(shmaddr);
    log(DEBUG,"detach shm done, shmaddr: 0x%x",shmaddr);

    close(fd);

    return 0;
}
